import Vue from 'vue'
import App from './App.vue'
import router from './router'
import 'zone.js' // 务必在 qiankun 之前加载它
import { registerMicroApps, start, prefetchApps } from 'qiankun'

const getActiveRule = (hash) => (location) => location.hash.startsWith(hash)

// 注册微应用
registerMicroApps([
  {
    name: 'reactApp',
    entry: '//localhost:8081',
    container: '#subapp-container', // 微应用渲染的入口
    activeRule: '#/app-react'
  },
  {
    name: 'vue2App',
    entry: '//localhost:8082',
    container: '#subapp-container',
    activeRule: '#/app-vue2'
  },
  {
    name: 'angularApp',
    entry: '//localhost:8083',
    container: '#subapp-container',
    activeRule: '/app-angular'
  },
  {
    name: 'purehmltApp',
    entry: '//localhost:8084',
    container: '#subapp-container',
    activeRule: '/app-purehtml'
  }
])

// 启动 qiankun
start({
  prefetch: true,
  // prefetch: ['vue2App']
  // prefetch: 'all'
  // prefetch: false
})

// 预加载手动加载的微应用
prefetchApps([
  { name: 'app1', entry: '//localhost:8085' },
  { name: 'app2', entry: '//localhost:8086' },
])

Vue.config.productionTip = false

new Vue({
  router,
  render: (h) => h(App)
}).$mount('#app')
